package com.apps.ftapp.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.apps.ftapp.R;
import com.apps.ftapp.adapter.Singleton;
import com.apps.ftapp.adapter.SucModelAdapter;
import com.apps.ftapp.util.ActivitySkipUtil;
import com.apps.ftapp.util.L;
import com.apps.ftapp.util.Timer;
import com.apps.ftapp.util.Tools;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 考试完成
 */
public class GestureFilpSucActivity extends BaseActivity {

    @BindView(R.id.gridView)
    GridView gridView;
    @BindView(R.id.tijiao)
    TextView tijiao;

    private SucModelAdapter sucModelAdapter;
    private List<Map> dataList = new ArrayList<>();
    private int unanswer = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gesture_filp_suc);
        ButterKnife.bind(this);


        commTitle.setVisibility(View.GONE);

        daojishi.setVisibility(View.VISIBLE);
        relativeLayout.setVisibility(View.VISIBLE);


        Timer timer = new Timer(daojishi);
        timer.start(daojishi);


        tijiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (unanswer > 0) {
                    new MaterialDialog.Builder(GestureFilpSucActivity.this)
                            .title(R.string.title1)
                            .content("您还有" + unanswer + "道题没有答题，确认提交？")
                            .positiveText(R.string.agree)
                            .positiveColor(Color.BLACK)
                            .negativeColor(Color.BLACK)
                            .negativeText(R.string.disagree)
                            .onAny(new MaterialDialog.SingleButtonCallback() {
                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    if (which == DialogAction.NEUTRAL) {
                                    } else if (which == DialogAction.POSITIVE) {
                                        ActivitySkipUtil.skipAnotherActivity(GestureFilpSucActivity.this,
                                                SubjectResultActivity.class, true);
                                    } else if (which == DialogAction.NEGATIVE) {
                                    }

                                }
                            })
                            .show();
                } else {
                    ActivitySkipUtil.skipAnotherActivity(GestureFilpSucActivity.this, SubjectResultActivity.class, true);
                }
            }
        });

        initView();

    }

    private void initView() {

        Singleton s = Singleton.getInstance();
//        for(int i=0;i<6;i++){
//            Map m = new HashMap();
//            m.put("index",i+1);
//            if(i==2||i==5)
//                m.put("is",false);
//            else
//                m.put("is",true);
//            s.addD(m);
////            dataList.add(m);
//        }
        s.setEndTime(Tools.getTime1());
        dataList = s.getDatiList();
        for (int i = 0; i < dataList.size(); i++) {
            Map temp = dataList.get(i);
            if (Tools.isBooleanNull(temp.get("is")) == false) {
                unanswer++;
            }
        }

        L.i("main", "....." + s.getKeys());


        sucModelAdapter = new SucModelAdapter(getApplicationContext(), dataList, s.getKeys());
        gridView.setAdapter(sucModelAdapter);

    }
}
